<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>transition in class change</title>
    <style>
      #test01 {
        position: relative;
        width: 200px;
        height: 200px;
        background: red;
        transition: all 1s ease;
      }

      #test01.change {
        width: 400px;
        height: 400px;
        background-color: lightblue;
      }

      .child {
        width: 100px;
        height: 100px;
        background: green;
        position: absolute;
        transition: all 1s ease;
      }

      #test01.change .child {
        top: 100px;
        width: 100%;
      }
    </style>
  </head>
  <body>
    <button id="toggle_test01">切换01</button>
    <div id="test01">
      <div class="child"></div>
    </div>

    <script>
      document
        .getElementById("toggle_test01")
        .addEventListener("click", function () {
          document.getElementById("test01").classList.toggle("change");
        });
    </script>
  </body>
</html>
